﻿/*
 * @Descripttion: 
 * @version: 
 * @Author: MichaelHu
 * @Date: 2022-01-19 15:55:45
 * @LastEditors: MichaelHu
 * @LastEditTime: 2022-08-15 18:15:48
 */
#ifndef LUA_LVGL_LIB
#define LUA_LVGL_LIB

#include "../lua/lauxlib.h"
#include "../lua/lua.h"
#include "../lua/lualib.h"
#include "../lvgl/lvgl.h"

#define LUA_USER_DEBUG

#ifdef LUA_USER_DEBUG
#define LUA_USER_PRINT(...) \
    printf(__VA_ARGS__);    \
    printf("\r\n")
#else
#define LUA_USER_PRINT(...)
#endif

lua_State *lua_getstate(void);

#define META_STR "lvgl"
#define META_ANIM "anim"
#define META_STYLE "style"

#define META_ARC "arc"
#define META_BAR "bar"
#define META_BTN "btn"
#define META_BTNMATRIX "btnmatrix"
#define META_CANVAS "canvas"
#define META_CHECKBOX "checkbox"
#define META_DROPDOWN "dropdown"
#define META_IMG "img"
#define META_LABEL "label"
#define META_LINE "line"
#define META_OBJX_TEMPL "objx_templ"
#define META_ROLLER "roller"
#define META_SLIDER "slider"
#define META_SWITCH "switch"
#define META_TABLE "table"
#define META_TEXTAREA "textarea"

typedef struct luaH_Reg_enum
{
    const char *name;
    lua_Integer value;
} luaH_Reg_enum;

typedef struct luaH_Reg_enum_string
{
    const char *name;
    const char *value;
} luaH_Reg_enum_string;

static void add_enum(lua_State *L, const luaH_Reg_enum *l)
{
    for (; l->name != NULL; l++)
    {
        lua_pushinteger(L, l->value);
        lua_setfield(L, -2, l->name);
    }
}

static void add_enum_string(lua_State *L, const luaH_Reg_enum_string *l)
{
    for (; l->name != NULL; l++)
    {
        lua_pushstring(L, l->value);
        lua_setfield(L, -2, l->name);
    }
}

#define LUA_LV_CREAT_RLT {"obj", lua_lv_obj_create},             \
                         {"arc", lua_lv_arc_create},             \
                         {"bar", lua_lv_bar_create},             \
                         {"btn", lua_lv_btn_create},             \
                         {"btnmatrix", lua_lv_btnmatrix_create}, \
                         {"canvas", lua_lv_canvas_create},       \
                         {"checkbox", lua_lv_checkbox_create},   \
                         {"dropdown", lua_lv_dropdown_create},   \
                         {"img", lua_lv_img_create},             \
                         {"label", lua_lv_label_create},         \
                         {"line", lua_lv_line_create},           \
                         {"roller", lua_lv_roller_create},       \
                         {"slider", lua_lv_slider_create},       \
                         {"switch", lua_lv_switch_create},       \
                         {"table", lua_lv_table_create},         \
                         {"textarea", lua_lv_textarea_create},   \
                         {META_ANIM, lua_lv_anim_create},        \
                         {META_STYLE, lua_lv_style_create}

#define LUA_LV_OBJ_RLT {"center", lua_lv_obj_center},     \
                       {"align", lua_lv_obj_align},       \
                       {"size", lua_lv_obj_size},         \
                       {"width", lua_lv_obj_set_width},   \
                       {"height", lua_lv_obj_set_height}, \
                       {"pos", lua_lv_obj_set_pos},       \
                       {"x", lua_lv_obj_set_x},           \
                       {"y", lua_lv_obj_set_y},           \
                       {"obj_del", lua_lv_obj_del},       \
                       {"__gc", lua_auto_gc}

#endif
